home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 12 / 012.d81 / pps #28 < prev    next >
Text File  |  2022-08-26  |  7KB  |  356 lines

  1.  
  2.  PEEKs, POKEs, and SYSes -- Part 28
  3.    -- continued from Part 27 --
  4.  
  5.  
  6.  
  7.  
  8.   Now, let's say we were to run this
  9.  
  10. example program:
  11.  
  12.  
  13. 10 DIM AB(1,2),CD%(3),EF$(2)
  14.  
  15.  
  16. ======================================
  17. CHART 3:  What memory looks like after
  18.           we run the example program:
  19. --------------------------------------
  20. label     description      value  addr
  21. --------------------------------------
  22.  
  23. TXTTAB--> BASIC program line      2049
  24.           ten.
  25.           End of program.         2078
  26. VARTAB-->                         2079
  27. ARYTAB--> variable name "a"   65  2079
  28.           variable name "b"   66  2080
  29.        +<-offset pointer(lo)  39  2081
  30.        !  offset pointer(hi)   0  2082
  31.        !  # of dimensions      2  2083
  32.        !  size of dim 2 (hi)   0  2084
  33.        !  size of dim 2 (lo)   3  2085
  34.        !  size of dim 1 (hi)   0  2086
  35.        !  size of dim 1 (lo)   2  2087
  36.        !  ab(0,0) - 5 bytes   #0  2088
  37.        !  ab(1,0) - 5 bytes   #0  2093
  38.        !  ab(0,1) - 5 bytes   #0  2098
  39.        !  ab(1,1) - 5 bytes   #0  2103
  40.        !  ab(0,2) - 5 bytes   #0  2108
  41.        !  ab(1,2) - 5 bytes   #0  2113
  42.        +->variable name "c"  195  2118
  43.           variable name "d"  196  2119
  44.        +<-offset pointer(lo)  15  2120
  45.        !  offset pointer(hi)   0  2121
  46.        !  # of dimensions      1  2122
  47.        !  size of dim 1 (hi)   0  2123
  48.        !  size of dim 1 (lo)   4  2124
  49.        !  cd%(0) - 2 bytes    #0  2125
  50.        !  cd%(1) - 2 bytes    #0  2127
  51.        !  cd%(2) - 2 bytes    #0  2129
  52.        !  cd%(3) - 2 bytes    #0  2131
  53.        +->variable name "e"   69  2133
  54.           variable name "f"  198  2134
  55.        +<-offset pointer(lo)  16  2135
  56.        !  offset pointer(hi)   0  2136
  57.        !  # of dimensions      1  2137
  58.        !  size of dim 1 (hi)   0  2138
  59.        !  size of dim 1 (lo)   3  2139
  60.        !  ef$(0) - 3 bytes    ""  2140
  61.        !  ef$(1) - 3 bytes    ""  2143
  62.        !  ef$(2) - 3 bytes    ""  2146
  63. STREND<+                          2149
  64. ======================================
  65.  
  66.      And now for the explanation.
  67.  
  68.         (Drum roll please...)
  69.  
  70.      Let's take it from the top.
  71.  
  72.  
  73. Our BASIC program starts at TXTTAB
  74.  
  75. (address 2049) and extends to just
  76.  
  77. before VARTAB (address 2079).
  78.  
  79.   VARTAB and ARYTAB point to the same
  80.  
  81. place because our sample program used
  82.  
  83. no simple variables.  If we HAD used
  84.  
  85. simple variables, they would be found
  86.  
  87. somewhere between VARTAB and ARYTAB.
  88.  
  89.  
  90. THE FIRST ARRAY: AB
  91.  
  92.  
  93.   The first array our program used was
  94.  
  95. AB(1,2).  So, the address pointed to
  96.  
  97. by ARYTAB contains the name of our
  98.  
  99. array.  As you recall from our
  100.  
  101. discussion of simple variables, the
  102.  
  103. names of real variables have their
  104.  
  105. high bits turned off.  On our chart,
  106.  
  107. at location 2079, 65 is the ASCII
  108.  
  109. value of "A".  At 2080 we find 66, the
  110.  
  111. ASCII value of "B".
  112.  
  113.   The next two bytes of memory, 2081
  114.  
  115. and 2082, contain the offset to the
  116.  
  117. address of the name of the next
  118.  
  119. array.  2081 is the low byte and 2082
  120.  
  121. the high, so to find the address of
  122.  
  123. the the SECOND array, add 39 (the
  124.  
  125. contents of 2082) to 2079 (the address
  126.  
  127. of the FIRST array).  If you don't
  128.  
  129. get 2118, try again.  A glance at our
  130.  
  131. chart shows that the name of the next
  132.  
  133. array used (CD%) is, indeed, at 2118.
  134.  
  135.   But let's look at the FIRST array
  136.  
  137. some more.  Byte 2083 describes the
  138.  
  139. number of dimensions.  Its value is
  140.  
  141. two because array AB had two
  142.  
  143. subscripts.
  144.  
  145.   The next four bytes (2084 to 2087)
  146.  
  147. tell us the size of each of AB's
  148.  
  149. dimensions.  It takes two bytes per
  150.  
  151. dimension to describe the size of
  152.  
  153. the array so the size of this block
  154.  
  155. will vary.  For array AB, 2084-85 tell
  156.  
  157. us that the rightmost dimension has
  158.  
  159. three elements (0, 1, and 2).  2086-87
  160.  
  161. describe the second dimension from
  162.  
  163. the right.  It has two elements (0 and
  164.  
  165. 1).
  166.  
  167.   Starting at 2088, we find the actual
  168.  
  169. values of the array variables.  Array
  170.  
  171. AB is a REAL array, so each variable
  172.  
  173. is represented by five bytes.  (You
  174.  
  175. will remember from our discussion of
  176.  
  177. simple variables that a real variable
  178.  
  179. consists of an exponent byte followed
  180.  
  181. by four mantissa bytes.)  Arrays are
  182.  
  183. stored with the rightmost index
  184.  
  185. increasing most slowly.  Look at
  186.  
  187. locations 2088 to 2113 to see what I'm
  188.  
  189. talking about.  This array is two
  190.  
  191. elements by three elements, so there
  192.  
  193. are six variables reserved.  Six
  194.  
  195. variables times five bytes... hmmm...
  196.  
  197. The next thirty bytes from 2088 will
  198.  
  199. contain the values of all the
  200.  
  201. variables in array AB.
  202.  
  203.   2088 plus 30 is 2118.  That's where
  204.  
  205. our next array will start.  You may
  206.  
  207. remember that our offset pointer from
  208.  
  209. the first array pointed to 2118.  It
  210.  
  211. turns out that array offset pointers
  212.  
  213. always point to the next memory
  214.  
  215. location after the end of their own
  216.  
  217. array.
  218.  
  219.  
  220.  
  221. THE SECOND ARRAY: CD%
  222.  
  223.   The second array our program used
  224.  
  225. was called CD%, so we can expect to
  226.  
  227. find the ASCII values for "C" and "D"
  228.  
  229. in memory locations 2118 and 2119.
  230.  
  231. You will recall from our discussion of
  232.  
  233. simple variables that INTEGER names
  234.  
  235. have the high bit set in both
  236.  
  237. characters.
  238.  
  239.   2120 and 2121 are the offset from
  240.  
  241. second array to the third array.
  242.  
  243. (2118 + 15 = 2133 ... That's where
  244.  
  245. EF% should start.)
  246.  
  247.   2122 holds the number of dimensions
  248.  
  249. of array CD%.  In this case, there was
  250.  
  251. only one dimension.
  252.  
  253.   2123 and 2124 describe the size of
  254.  
  255. that single dimension -- 4 elements.
  256.  
  257. The size here will always be one
  258.  
  259. greater than the number used in the
  260.  
  261. BASIC DIM statement, because element
  262.  
  263. zero is always counted.
  264.  
  265.   The values of array CD% are stored
  266.  
  267. starting at 2125.  Because this is an
  268.  
  269. INTEGER array, only two bytes are
  270.  
  271. needed to hold the values.  Unlike
  272.  
  273. simple integers, subscripted integers
  274.  
  275. do NOT waste three bytes of memory
  276.  
  277. per variable.  The values of the four
  278.  
  279. variables in CD% are stored in the
  280.  
  281. eight memory locations from 2125 to
  282.  
  283. 2132.
  284.  
  285.  
  286.  
  287. THE THIRD ARRAY: EF$
  288.  
  289.   The first seven bytes of array EF$
  290.  
  291. are comparable to the first seven
  292.  
  293. of CD% -- since both arrays have the
  294.  
  295. same number of dimensions, both have
  296.  
  297. the same amount of overhead.
  298.  
  299.   Locations 2133 and 2134 contain the
  300.  
  301. name -- remember that only the SECOND
  302.  
  303. byte of a STRING name has the high
  304.  
  305. bit set.
  306.  
  307.   The offset pointer at 2135 and 2136
  308.  
  309. points to STREND.  That means there
  310.  
  311. are no more arrays after EF$.
  312.  
  313.   2137 through 2139 describe the size
  314.  
  315. of the array -- that stuff should be
  316.  
  317. old hat to you by now.
  318.  
  319.   2140 through 2148 contain the
  320.  
  321. string pointers for the three strings
  322.  
  323. of array EF$.  As you remember from
  324.  
  325. our discussion of simple variables,
  326.  
  327. the values of string variables are
  328.  
  329. not found with the variable name.
  330.  
  331. Instead, strings are stored between
  332.  
  333. FRETOP and MEMSIZ.  The only
  334.  
  335. information kept with a string's name
  336.  
  337. is the length of the string and the
  338.  
  339. address where its actual contents can
  340.  
  341. be found.
  342.  
  343.   In string arrays, each element holds
  344.  
  345. only these three bytes:
  346.  
  347. Byte 0:  The length of the string.
  348.  
  349. Byte 1:  The low byte of the string's
  350.          address.
  351.  
  352. Byte 2:  The high byte of the string's
  353.          address.
  354.  
  355. ------< continued in Part 29 >--------
  356.